<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>私有属性</title>
</head>

<body>
  <script>
    class Person {
      // 公有属性
      name;
      // 私有属性
      #age;
      #weight;
      // 构造方法
      constructor(name, age, weight) {
        this.name = name;
        this.#age = age;
        this.#weight = weight;
      }
      showMsg() {
        console.log(this.name)
        console.log(this.#age)
        console.log(this.#weight)
      }
    }

    const girl = new Person('小红', 18, '165');
    console.log(girl); // {name: '小红', #age: 18, #weight: '165'}
    console.log(girl.name); // 小红
    // console.log(girl.#age); // 报错 私有方法只能在class里访问
    girl.showMsg();
  </script>
</body>

</html>